//
//  HXCommandTCell.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/3.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXCommandTCell.h"
#import "HX_Macro.h"
#import "HXCommandCCell.h"
#import "UIView+Frame.h"
#import "HXTalentModel.h"
#define kCommandTcell @"commandReuse"
#import "UIImageView+WebCache.h"
@implementation HXCommandTCell
- (void)setCommandSource:(NSMutableArray *)commandSource {
    _commandSource = commandSource;
    [_collectionView reloadData];
}

- (void)setUp {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = 1;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.bounces = NO;
    _collectionView.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:_collectionView];
    [_collectionView registerNib:[UINib nibWithNibName:@"HXCommandCCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kCommandTcell];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.commandSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HXCommandCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCommandTcell forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    HXTalentModel *talentModel = self.commandSource[indexPath.row];
    [cell.personImage sd_setImageWithURL:[NSURL URLWithString:talentModel.head_img]];
    cell.name.text = talentModel.nick;
    cell.follow.text = [NSString stringWithFormat:@"粉丝数:%ld", talentModel.tongji_be_follow];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.contentView.frame.size.width / 4.4, self.collectionView.HX_height);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.rows(indexPath.row);
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
}
@end
